using System.IO;
using dnAnalytics.LinearAlgebra;
using dnAnalytics.LinearAlgebra.IO;

namespace dnAnalytics.Examples.LinearAlgebra.IO
{
    public sealed class MatrixMarketWriterOverall
    {
        public static void Main()
        {
            //create a MatrixMarketWriter that writes array formatted files
            IMatrixWriter arrayWriter = new MatrixMarketWriter(ExchangeFormat.Array, DataType.Real);

            //create a MatrixMarketWriter that writes coordinate formatted files
            IMatrixWriter coordWriter = new MatrixMarketWriter(ExchangeFormat.Coordinate, DataType.Real);

            //the matrix to write out
            Matrix matrix = MatrixBuilder.CreateMatrix(100, 100);

            //add data to the matrix
            //matrix[,] = ...

            //write the matrix to an array formatted file using a file name
            arrayWriter.WriteMatrix(matrix, "somefile.mtx");

            //write the matrix to a coordinate formatted file using aTextWriter
            using (TextWriter text = new StreamWriter("somefile.mtx"))
            {
                coordWriter.WriteMatrix(matrix, text);
            }
        }
    }
}